import axios from "axios"
import { NEWS_LIST } from "../constants/news"

export const getNewsAC = (payload) => ({
  type: NEWS_LIST,
  payload
})

export const getNews = (id) => async (dispatch) => {
  const {
    data: {
      data: { results }
    }
  } = await axios.get(`http://geek.itheima.net/v1_0/articles?channel_id=${id}&timestamp=${Date.now()}`)
  dispatch(getNewsAC(results))
}